<?php
/**
* Builds and sends the email for reservation reminders
* @author Nick Korbel <lqqkout13@users.sourceforge.net>
* @version 06-21-08
* @package phpScheduleIt
*
* Copyright (C) 2003 - 2007 phpScheduleIt & 2010 ITOxygen
* License: GPL, see LICENSE
*/

include_once('interfaces/IEmail.php');
include_once($basedir . '/lib/User.class.php');

class ReminderEmail extends IEmail
{
	var $_mailer = null;

	/**
	* Builds a reminder email object from a Reminder
	* @param IMailer $mailer the IMailer object to use for sending the email
	*/
	function ReminderEmail(&$mailer) {
		$this->_mailer =& $mailer;
	}

	function send() {
		$this->_mailer->Send();
	}

	function addAddress($address, $name = '') {
		$this->_mailer->AddAddress($address);
	}

	function addCC($address, $name = '') {
		die('Not implemented');
	}

	function addBCC($address, $name = '') {
		die('Not implemented');
	}

	function isHTML($isHtml = false) {
		$this->_mailer->IsHTML($isHtml);
	}

	function setFrom($address, $name = '') {
		$this->_mailer->From = $address;
		$this->_mailer->FromName = $name;
	}

	function setSubject($subject) {
		$this->_mailer->Subject = $subject;
	}

	function setBody($body) {
		$this->_mailer->Body = $body;
	}

	function buildFromReminder($reminder) {
		if (!$reminder->admin_closing) {
    $this->addAddress($reminder->email);
    }
    else
    {
    $user = new User();
    $adminemails = $user->db->get_admin_emails();
      for ($j = 0; $j < count($adminemails); $j++) {
        $this->addAddress($adminemails[$j]['email']);
      }
    }
		$this->setFrom($reminder->email);
		$this->setSubject($this->_buildSubject($reminder));
		$this->setBody($this->_buildBody($reminder));
		$this->isHTML(false);
	}

  function buildFromInviteReminder($reminder) {
		
    $this->addAddress($reminder->email);
    $this->setFrom($reminder->email);
		$this->setSubject($this->_buildInviteSubject($reminder));
		$this->setBody($this->_buildInviteBody($reminder));
		$this->isHTML(false);
	}


	function _buildSubject($reminder) {
		return translate('Reminder Subject',
			array(
			$reminder->title,
			Time::formatDate($reminder->start_date, '', false, $reminder->timezone),
			Time::formatTime($reminder->start_time, '',true, $reminder->timezone)
			)
		);
	}

	function _buildBody($reminder) {
		return translate_email('Reminder Body',
			$reminder->title,
			Time::formatDate($reminder->start_date, '', false, $reminder->timezone),
			Time::formatTime($reminder->start_time, '', true, $reminder->timezone),
			Time::formatDate($reminder->end_date, '', false, $reminder->timezone),
			Time::formatTime($reminder->end_time, '', true, $reminder->timezone)
		);
	}
	
	function _buildInviteSubject($reminder) {
		return translate('Invite Reminder Subject',
			array(
			$reminder->title,
			Time::formatDate($reminder->start_date, '', true, $reminder->timezone),
			Time::formatTime($reminder->start_time, '',true, $reminder->timezone)
			)
		);
	}

	function _buildInviteBody($reminder) {
		return translate_email('Invite Reminder Body',
			$reminder->title,
			Time::formatDate($reminder->start_date, '', true, $reminder->timezone),
			Time::formatTime($reminder->start_time, '', true, $reminder->timezone),
			Time::formatDate($reminder->end_date, '', true, $reminder->timezone),
			Time::formatTime($reminder->end_time, '', true, $reminder->timezone)
		);
	}
	
}
?>
